import { uploadResume } from "@/service/chat";
import { fileOpen } from "browser-fs-access";
async function uploadFile() {
  return new Promise(async (resolve, reject) => {
    const arrFile = await fileOpen({
      extensions: [".png", ".jpg", ".jpeg", ".webp", ".pdf", ".doc", ".docx"],
      // Set to `true` for allowing multiple files, defaults to `false`.
      multiple: false,
      // Textual description for file dialog , defaults to `''`.
      description: "resume files",
    });
    console.log(arrFile);
    // let fileHandle = arrFileHandle.handle;
    // const fileData = await fileHandle.getFile();
    let fd = new FormData();
    fd.append("resume", arrFile);
    uploadResume(fd)
      .then((res) => {
        return resolve(res);
      })
      .catch((err) => {
        reject(err);
      });
  });
  // https://www.zhangxinxu.com/wordpress/2021/08/file-system-access-api/
  // https://developer.mozilla.org/en-US/docs/Web/API/Window/showOpenFilePicker
}

export default uploadFile;
